﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data.MySqlClient;

namespace TenpointSystem.Common.Db
{
    class MySqlHelper
    {
        private static MySqlDataAdapter adapter = null;
        private static MySqlCommand command = null;

        public static T selectOne<T>(MySqlParam param, RowMapper<T> rp) where T : new()
        {
            adapter = new MySqlDataAdapter();
            command = new MySqlCommand();
            command.CommandText = param.sql;
            command.Parameters.AddRange(param.sqlparam);
            command.Connection = MySqlConnector.getConnection();
            adapter.SelectCommand = command;
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return rp.extractData( dt, 0 );
        }
    }
}
